/**
 * Copyright [2012-2013] [Guðmundur Björn Birkisson]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. Copyright [2012-2013] [Guðmundur Björn Birkisson]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * ---------------------------------------------------------------------------
 * 
 * Class name:  KarelMap
 * 
 * Description of class:
 * 
 * Class that represent a map of tiles.
 * 
 */

package karel.gamelogic.world;

import java.awt.geom.Point2D;
import java.io.Serializable;

public class KarelMap implements Serializable {

    public int WIDTH;
    public int HEIGHT;
    public Tile[][] data;

    public KarelMap(Tile[][] data, int width, int height) {
        this.data = data;
        this.WIDTH = width;
        this.HEIGHT = height;
    }
    
    public int pickUpRock(Point2D point) {
        return pickUpRock((int) point.getX(), (int) point.getY());
    }

    public int pickUpRock(int x, int y) {
        if (data[x][y].checkIfRock()) {
            data[x][y].removeRock();
            return 1;
        }
        return 0;
    }

    public void putDownRock(Point2D point) {
        putDownRock((int) point.getX(), (int) point.getY());
    }

    public void putDownRock(int x, int y) {
        data[x][y].addRock();
    }

    public int getNumberOfRocks(int x, int y) {
        return data[x][y].getNrOfRocks();
    }

    public int getWidth() {
        return WIDTH;
    }

    public int getHeight() {
        return HEIGHT;
    }

    public boolean isType(int x, int y, Tile.Type type) {
        return data[x][y].getType() == type;
    }

    public boolean isType(Point2D point, Tile.Type type) {
        return isType((int) point.getX(), (int) point.getY(), type);
    }

    @Override
    public String toString() {
        String res = "";
        for (int i = 0; i < WIDTH; i++) {
            for (int j = 0; j < HEIGHT; j++) {
                res += data[i][j] + " ";
            }
            res += "\n";
        }
        return res;
    }
}
